# Contributor: Bart Ribbers <bribbers@disroot.org>
# Contributor: knuxify <knuxify@gmail.com>
# Maintainer: Sertonix <sertonix@posteo.net>
pkgname=prismlauncher
pkgver=9.1
pkgrel=0
_libnbtplusplus_commit=23b955121b8217c1c348a9ed2483167a6f3ff4ad
pkgdesc="A custom launcher for Minecraft that allows you to easily manage multiple installations of Minecraft at once"
url="https://prismlauncher.org/"
# riscv64, loongarch64: blocked by openjdk
arch="all !riscv64 !loongarch64"
license="GPL-3.0-only AND Apache-2.0"
depends="
	java-jre
	qt6-qtimageformats
	qt6-qtsvg
	"
makedepends="
	cmake
	cmark-dev
	extra-cmake-modules
	qt6-qtbase-dev
	qt6-qt5compat-dev
	qt6-qtimageformats-dev
	qt6-qtnetworkauth-dev
	openjdk8
	quazip-dev
	samurai
	scdoc
	tomlplusplus-dev
	"
case "$CARCH" in
armv7|armhf) makedepends="$makedepends clang" ;; # fails to build with gcc, see note in build()
esac
install="$pkgname.post-upgrade"
source="$pkgname-$pkgver.tar.gz::https://github.com/PrismLauncher/PrismLauncher/archive/refs/tags/$pkgver.tar.gz
	libnbtplusplus-$_libnbtplusplus_commit.tar.gz::https://github.com/PrismLauncher/libnbtplusplus/archive/$_libnbtplusplus_commit.tar.gz
	0001-system-jemalloc.patch
	0002-native-openal-lwjgl-2.patch
	0003-use-system.patch
	0004-disable-ghc-filesystem.patch

	README.alpine
	"
subpackages="$pkgname-doc"
builddir="$srcdir/PrismLauncher-$pkgver"

prepare() {
	rmdir libraries/libnbtplusplus
	ln -s "$srcdir"/libnbtplusplus-$_libnbtplusplus_commit libraries/libnbtplusplus

	default_prepare
}

build() {
	case "$CARCH" in
	armv7|armhf)
		# building with gcc fails, see https://github.com/PrismLauncher/PrismLauncher/issues/128
		export CC=clang
		export CXX=clang++
		;;
	esac

	JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DLauncher_QT_VERSION_MAJOR=6 \
		-DLauncher_BUILD_PLATFORM=alpinelinux \
		-DLauncher_ENABLE_JAVA_DOWNLOADER_DEFAULT=OFF
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	install -Dm644 "$srcdir"/README.alpine -t "$pkgdir"/usr/share/doc/$pkgname
}

sha512sums="
d3febf7ead499c26e74d963a910f993354209da4c32639a247dfdad4a20b5049c30995586af87c15d4115add6b70f0ccf29a77ec52b6478747371d75a7875d66  prismlauncher-9.1.tar.gz
ea18c2b4016d078c19337cedc3b2563e2eeaf4dfbb452812bc1d4022544df03c3376219a706e7a7da39144d8d20bde2f8780e382f0abf68191a04c52358af0f8  libnbtplusplus-23b955121b8217c1c348a9ed2483167a6f3ff4ad.tar.gz
d0e40b01e9bff51e2454302314b5c316556cdd40928df89446c7ecb531a1a8f3fd02cad9f39641f3bbffad1fd0ae2508bc7386ef19afaccff338a88598481155  0001-system-jemalloc.patch
bf8b5a7592b6866e9fd2d32716daea812435eaae472a1dd36047e8ae11bf10be4183910ac274f27c3e5c2133efd75fe5002fc2db7d91af42c85ab67c4725c20c  0002-native-openal-lwjgl-2.patch
87e72332a74476cb4b0f4761c76725a3c8ff60723dc58073387d38040a9b5d5317da70a9cebff1cdad5efd6cdeddc9719882d526f32af4efaef3f9251019de01  0003-use-system.patch
0398fd04e6ff3e11d05d4b504f39f8f5d13f7b396d72fd5d19df850b253ac7e265133169f641185a72fbb54388d5803a66ee0d1d394bbf5bb14e575d262004c2  0004-disable-ghc-filesystem.patch
ef1b7c17f39c10b7db73cf03ba25e2b4f683a56fcd7d14cc3bed1d70f574ccaa1021632b01331468f490b42996bbc28972fe98dfc3ea6bcd5f8db6b499fff137  README.alpine
"
